﻿using System;
using System.Collections.Generic;
using System.Linq;
using MvcLibrary.Repository;
using System.Web;
using System.IO;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations;
using System.Collections;


namespace WebVideo.Models
{
    public class ForgetPassModel
    {
        [Required(ErrorMessage = "*")]
        [StringLength(20, ErrorMessage = "Password {1}-{2} kí tự", MinimumLength = 6)]
        public string Pass { get; set; }


        [Required(AllowEmptyStrings = false, ErrorMessage = "*")]
        [Compare("Pass", ErrorMessage = "*")]
        public string ConfirmPassword { get; set; }

        public string Link { get; set; }
        public string HasCode { get; set; }

        public static void KP(ForgetPassModel khoat)
        {
            dbVideoDataContext db = new dbVideoDataContext();
            Security ser = new Security();
            var KH = db.EntityUsers.Where(p => p.Link == khoat.Link);
            if (KH.ToList().Count > 0)
            {
                EntityUser us = db.EntityUsers.Where(p => p.Link == khoat.Link).Single();
                us.Pass = ser.GetHashPassword(khoat.Pass);
                db.SubmitChanges();
            }
            else
            {
                EntityBusiness us = db.EntityBusinesses.Where(p => p.HasCode == khoat.Link).Single();
                us.Pass = ser.GetHashPassword(khoat.Pass);
                db.SubmitChanges();
            }


        }
    }
}